-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix multiindex level serialization after reset_index #8672
Fix multiindex level serialization after reset_index #8672
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't fully understand but happy to defer to you.
This does not seem to have fixed xarray-contrib/xeofs#148, which worked prior to 2024.1.0 |
@slevang could you provide an example (MVCE), please? |
An MCVE with import xarray as xr
import xeofs
data = xr.tutorial.open_dataset('air_temperature').air
model = xeofs.models.EOF(n_modes=10)
model.fit(data, "time")
model.save("test.zarr")
I'm trying to figure out a pure xarray version though. We should just be doing the same |
Looks like the key difference is that in the previous issue, |
Ok, we are still raising that error (and we shouldn't do so) in the case where a reset multi-index level coordinate has been renamed to its dimension: import pandas as pd
import xarray as xr
midx = pd.MultiIndex.from_product([["a", "b"]], names=["foo"])
coords = xr.Coordinates.from_pandas_multiindex(midx, "x")
ds = xr.Dataset(coords=coords)
ds_reset = ds.reset_index("x").rename_vars(foo="x")
type(ds_reset.x.variable._data)
# xarray.core.indexing.PandasMultiIndexingAdapter
ds_reset.to_netcdf("test.nc")
# error Instead of adding more checks like in this PR, I think that a proper fix would be to unwrap the multi-index level coordinate variable data from |
@benbovy any more guidance on how to go about fixing this edge case? I can try a PR but am pretty unfamiliar with the new indexers. |
whats-new.rst